﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity.ModelConfiguration;
using Studio7i.Dominio;

namespace Studio7i.Persistencia.EF.ORM
{
    public class SalaMapping : EntityTypeConfiguration<Sala>
    {
        public SalaMapping()
            : base()
        {
            ToTable("sala");
            HasKey(s => s.Codigo);
            Property(s => s.Codigo)
                .HasColumnName("codigo")
                .IsRequired()
                .HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.DatabaseGeneratedOption.None);
            Property(s => s.Nombre)
                .HasColumnName("nombre")
                .IsRequired();
            Property(s => s.Caracteristicas)
                .HasColumnName("caracteristicas")
                .IsRequired();
            Property(s => s.Capacidad)
                .HasColumnName("capacidad")
                .IsRequired();
            HasRequired(s => s.Local)
                .WithMany()
                .Map(s => s.MapKey("local"));
            Property(s => s.Comentarios)
                .HasColumnName("comentarios");
            HasMany<Instrumento>(s => s.Instrumentos)
                .WithMany(i => i.Salas)
                .Map(m => m.ToTable("sala_instrumento")
                    .MapLeftKey("sala")
                    .MapRightKey("instrumento"));
        }
    }
}